<template>
    <div class="group-component">
        <div class="content">
            <div class="title">工作场景主题解读</div>
            <div class="content">
                <div class="desc">{{ content }}</div>

                <ul class="link-box">
                    <li>包含{{ num }}个学习内容 <i v-if="num === null" class="el-icon-loading"></i></li>
                    <li @click="toView">概览该工作场景主题学习页</li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        content: {
            type: String,
            default: '',
        },
        id: {
            type: Number,
            default: 0,
        },
        show: {
            type: Boolean,
            default: false,
        },
    },
    watch: {
        show(val) {
            if (val) this.fetchData();
        },
    },
    data() {
        return {
            loading: false,
            num: null,
        };
    },
    methods: {
        async fetchData() {
            this.loading = true;
            const data = await API.get(`label/section/${this.id}`);
            this.num = data.length || 0;
            this.loading = false;
        },
        toView() {
            this.$emit('toView');
        },
    },
    mounted() {
    },
};
</script>

<style lang="scss" scoped>
.group-component {
    width: 700px;
    padding: 13px 11px;
    box-sizing: border-box;

    .content {
        margin-bottom: 23px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    .title {
        font-size: 16px;
        margin-bottom: 10px;
    }

    .desc {
        font-size: 12px;
    }

    .link-box {
        list-style-type: disc;
        margin-top: 17px;
        padding-left: 16px;
        box-sizing: border-box;

        li {
            width: fit-content;
            height: 17px;
            margin-bottom: 8px;
            box-sizing: border-box;
            padding-bottom: 1px;

            &:last-child {
                margin-bottom: 0;
                cursor: pointer;

                &:hover {
                    border-bottom: 1px solid #fff;
                }
            }
        }
    }
}
</style>
